function updateagent(k, iter)


global u v w du dv dw a b c dt h m x y dx dy s1 s2 s3 Gu Gv Gw x_best y_best g_best 

j = round(y(k)/h);
i = round(x(k)/h);

if i > m
    i = m;
    x(k) = m*h;
end
if i < 1
    i = 1;
    x(k) = 1;
end
if j > m
    j = m;
    y(k) = m*h;
end
if j < 1
     j = 1;
    y(k) = 1;
   
end

if iter > 0
    
    % update g_best
    if w(i,j) >= g_best
        x_best = x(k);
        y_best = y(k);
        g_best = w(i,j);
    end

    % update p_best
    if w(i,j) >= s3(k)
        s1(k) = x(k);
        s2(k) = y(k);
        s3(k) = w(i,j);
    end
    
    r = .2*rand(1,4);
    
    dx(k) = .1*dx(k) + .2*r(1)*(x_best - x(k)) + .2*r(3)*(u(i,j) - x(k));
    dy(k) = .1*dy(k) + .2*r(2)*(y_best - y(k)) + .2*r(4)*(v(i,j) - y(k));
    %u(i,j) = s1(k);
    %v(i,j) = s2(k);
end


%w(i,j) = 5;

end